package org.budo.graph.entity;

import java.util.LinkedHashMap;
import java.util.Map;

import org.budo.graph.metric.Metric;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lmw
 */
@Getter
@Setter
public class MetricGraph {
    public static final String GRAPH_TYPE = "METRIC";

    private static final String EXECUTE_COUNT = "ExecuteCount", EXECUTE_TIME_NANOS = "ExecuteTimeNanos";

    public static final String[] TITLES = { EXECUTE_COUNT, EXECUTE_TIME_NANOS };

    private Long executeCount;

    private Long executeTimeNanos;

    public MetricGraph(Metric metric) {
        this.setExecuteCount(metric.getExecuteCount().longValue());
        this.setExecuteTimeNanos(metric.getExecuteTimeNanos().longValue());
    }

    public Map<String, String> minus(MetricGraph lastMetricGraph) {
        Map<String, String> minusMap = new LinkedHashMap<String, String>(); // 这里应该是需要有序的Map的，顺序应该和 TITLES 一致
        minusMap.put(EXECUTE_COUNT, (this.getExecuteCount() - lastMetricGraph.getExecuteCount()) + ""); // 这里存储的是增量
        minusMap.put(EXECUTE_TIME_NANOS, (this.getExecuteTimeNanos() - lastMetricGraph.getExecuteTimeNanos()) + ""); // 这里存储的是增量
        return minusMap;
    }
}